/*
 * Copyright (C) 2018 wxyz <hyhjwzx@126.com>
 * This program can be distributed under the terms of the GNU GPL Version 2.
 * See the file LICENSE.
 *
 */

package ren.wxyz.study.euler.hp01;

import ren.wxyz.study.euler.base.IProblem;
import ren.wxyz.study.euler.util.ConsoleHelper;
import ren.wxyz.study.euler.util.MathHelper;

/**
 * 第 3 题
 *
 * @auther wxyz 2018-02-28_20:27
 * @since 1.0
 */
public class P003 implements IProblem {

    @Override
    public void main(String[] args) throws Throwable {
        long maxNumber = Long.parseLong(args[0]);
        long maxPrime = maxNumber;

        long middleNumber = (long) Math.sqrt(maxNumber);
        for (int i = 2; i <= middleNumber && i < maxPrime; i++) {
            // 判断质数
            if (!MathHelper.isPrimeNumber(i)) {
                continue;
            }

            // 短除法
            while (maxPrime > 2) {
                if (maxPrime % i == 0) {
                    maxPrime = maxPrime / i;
                }
                else {
                    break;
                }
            }
        }

        ConsoleHelper.print("maxPrime = " + maxPrime);
    }
}
